<?php
class media_draft_log {

	var $CI;
	var $media_draft_model;
	var $operation_log;

	public function __construct() {
		$this->CI =& get_instance();
		$this->CI->load->model("media/media_draft_model");
		$this->CI->load->library("sys/operation_log");
		$this->media_draft_model =$this->CI->media_draft_model;
		$this->operation_log =$this->CI->operation_log;
	}

	public function  insert_log($media_draft_id,$action_type,$create_by,$create_time,$explanation,$org_draft='',$draft=''){
		$differents='';
		if ($org_draft!='') {
			$differents=$this->get_differents($org_draft, $draft);
		}
		
		$log_info =array(	"unique_id"=>$this->query_media_draft_unique_id($media_draft_id),
							"explanation"=>$explanation,
							"operation_type"=>$action_type,
							"differents"=>$differents,
							"create_by"=>$create_by,
							"create_time"=>$create_time
						);
		$this->operation_log->insert_log($log_info);
		
	}


	public function query_media_draft_unique_id($media_draft_id){
		return $this->media_draft_model->query_media_draft_unique_id($media_draft_id);
	}
	public function delete_log($media_draft_id){
		$this->media_draft_log_model->delete_log($media_draft_id);
	}
	public function get_logs($media_draft_id){
		return $this->operation_log->get_logs($this->query_media_draft_unique_id($media_draft_id));
	}
	public function get_differents($org_draft,$draft){
		$differents="";
		if ($org_draft['province']!=$draft['province']) {
			$differents.="修改了 所属省份<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['province']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['province']."</span><br />";
		}
		if ($org_draft['city']!=$draft['city']) {
			$differents.="修改了 市<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['city']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['city']."</span><br />";
		}
		if ($org_draft['region']!=$draft['region']) {
			$differents.="修改了 地区/县镇<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['region']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['region']."</span><br />";
		}
		if ($org_draft['longitude']!=$draft['longitude']||$org_draft['latitude']!=$draft['latitude']) {
			$differents.="修改了 媒体坐标<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['longitude']." , ".$org_draft['latitude']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['longitude']." , ".$draft['latitude']."</span><br />";
		}
		if ($org_draft['location']!=$draft['location']) {
			$differents.="修改了 详细地址<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['location']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['location']."</span><br />";
		}
		if ($org_draft['media_type_id']!=$draft['media_type_id']) {
			$differents.="修改了 媒体类型<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['media_type_id']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['media_type_id']."</span><br />";
		}
		if ($org_draft['crafts']!=$draft['crafts']) {
			$differents.="修改了 制作工艺<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['crafts']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['crafts']."</span><br />";
		}
		if ($org_draft['corner_case']!=$draft['corner_case']) {
			$differents.="修改了 转角情况<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['corner_case']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['corner_case']."</span><br />";
		}
		if ($org_draft['specification_width']!=$draft['specification_width']) {
			$differents.="修改了 媒体宽度<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['specification_width']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['specification_width']."</span><br />";
		}
		if ($org_draft['specification_height']!=$draft['specification_height']) {
			$differents.="修改了 媒体高度<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['specification_height']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['specification_height']."</span><br />";
		}
		if ($org_draft['specification']!=$draft['specification']) {
			$differents.="修改了 媒体规格<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['specification']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['specification']."</span><br />";
		}
		if ($org_draft['media_area']!=$draft['media_area']) {
			$differents.="修改了 媒体面积<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['media_area']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['media_area']."</span><br />";
		}
		if ($org_draft['illumination']!=$draft['illumination']) {
			$org_draft['illumination'] =$org_draft['illumination']=="0"?"无照明":"有照明";
			$draft['illumination'] =$draft['illumination']=="0"?"无照明":"有照明";
			$differents.="修改了 照明情况<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['illumination']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['illumination']."</span><br />";
		}
		if ($org_draft['flow']!=$draft['flow']) {
			if ($org_draft['flow']=="10") {
				$org_draft['flow']="极大";
			}elseif ($org_draft['flow']=="20"){
				$org_draft['flow']="较大";
			}
			elseif ($org_draft['flow']=="30"){
				$org_draft['flow']="一般";
			}
			elseif ($org_draft['flow']=="40"){
				$org_draft['flow']="较小";
			}
			if ($draft['flow']=="10") {
				$draft['flow']="极大";
			}elseif ($draft['flow']=="20"){
				$draft['flow']="较大";
			}
			elseif ($draft['flow']=="30"){
				$draft['flow']="一般";
			}
			elseif ($draft['flow']=="40"){
				$draft['flow']="较小";
			}
			$differents.="修改了 人车流量<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['flow']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['flow']."</span><br />";
		}
		if ($org_draft['reference_price']!=$draft['reference_price']) {
			$differents.="修改了 参考价格<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['reference_price']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['reference_price']."</span><br />";
		}
		

		if ($org_draft['sketch_map']!=$draft['sketch_map']) {
			$differents.="修改了 媒体示意图<br/>";
		}
		if ($org_draft['vendor']!=$draft['vendor']) {
			$differents.="修改了 供应商<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['vendor']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['vendor']."</span><br />";
		}
		if ($org_draft['highway_id']!=$draft['highway_id']) {
			$differents.="修改了 所属高速<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['highway_id']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['highway_id']."</span><br />";
		}
		if ($org_draft['section_id']!=$draft['section_id']) {
			$differents.="修改了 高速路段<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['section_id']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['section_id']."</span><br />";
		}
		if ($org_draft['point_id']!=$draft['point_id']) {
			$differents.="修改了 关卡点位<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['point_id']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['point_id']."</span><br />";
		}
		if ($org_draft['airport_id']!=$draft['airport_id']) {
			$differents.="修改了 所属机场<br/>";
			$differents.="旧值为:<span class='invalid_log'>".$org_draft['airport_id']."</span><br />";
			$differents.="新值为:<span class='success_log'>".$draft['airport_id']."</span><br />";
		}
		
		return $differents;
	}
}